home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5844 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  44 lines

  1. Newsgroups: comp.lang.c++
  2. Path: hearst.acc.Virginia.EDU!maxwell!gcl8a
  3. From: gcl8a@Virginia.EDU (Gregory Carl Lewin)
  4. Subject: More ?'s re: copy ctor
  5. Message-ID: <DMD0Kq.LHx@Virginia.EDU>
  6. Organization: University of Virginia
  7. Date: Tue, 6 Feb 1996 15:05:14 GMT
  8.  
  9. When writing copy constructors for derived classes, it makes
  10. sense to use the existing copy ctor's for the base classes
  11. (thank you C++ FAQ's and everybody who responded to my question
  12. a month ago).  However, I am confused about hoto do this with
  13. multiple inheritance.  I have the following class tree:
  14.  
  15. class Base {...};  //includes copy ctor
  16. class D1 : virtual Base (...};  //w/copy ctor
  17. class D2 : virtual Base {...};  //""
  18. class DD : public D1, public D2 {...};
  19.  
  20. I have tried to write the copy ctor for DD as
  21.  
  22. DD::DD(const DD& dd) : Base(dd), D1(dd), D2(dd)
  23.     {...}
  24.  
  25. Surprisingly, I do NOT get a compile error, which I expected
  26. because there should be no way to cast from DD to D2, right?
  27. (as in:
  28. void foo(D2* d2) 
  29. will not accept:
  30.  
  31. DD dd;
  32. foo(dd);
  33.  
  34. right?
  35.  
  36. I must admit I have not tried to run this code to see what
  37. happens.  Can anyone explain it to me?  Am I not as bright as
  38. my mother told me?
  39.  
  40. Reply here or to:
  41. GCL8A@virginia.edu
  42.  
  43. (pardon the syntax error in line 2)
  44.